// ignore_for_file: prefer_const_constructors, avoid_unnecessary_containers, avoid_print

import 'package:flutter/material.dart';
import 'package:junyeyishu/ui/login/QGCodeLoginPage.dart';
import 'package:junyeyishu/ui/login/QGLoginPage.dart';
import 'package:junyeyishu/ui/login/QGLoginPasswordPage.dart';

import 'package:junyeyishu/utils/utils.dart';

class QGLogOut extends StatefulWidget {
  const QGLogOut({super.key});

  @override
  State<QGLogOut> createState() => _QGLogOutState();
}

class _QGLogOutState extends State<QGLogOut> {
  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        GestureDetector(
            onTap: () {
              Navigator.of(context).pop();
            },
            child: Container(
              width: kScreenWidth,
              height: kScreenHeight,
              color: Color.fromRGBO(0, 0, 0, 0.6),
            )),
        Positioned(left: 25.rpx, top: 300.5.rpx,right: 25.rpx, child: buildLogOutPop(context))
      ],
    );
  }

  buildLogOutPop(context) {
    return SingleChildScrollView(
      child: Container(
        padding: EdgeInsets.fromLTRB(20.rpx, 45.rpx, 20.rpx, 25.rpx),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(20.rpx),
            color: Color(0xFF232A32)),
        child: Column(children: [
          buildTitle(),
          SizedBox(height: 34.rpx),
          buildButton(context)
        ]),
      ),
    );
  }

  buildTitle() {
    return Container(
      child: Text(
        '确定退出账号？',
        style: TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 16.rpx,
            color: Color(0xFFFFFFFF)),
      ),
    );
  }

  buildButton(context) {
    return Column(
      children: [
        TextButton(
            onPressed: () {
              User.logout();

                Navigator.of(context).pushAndRemoveUntil(
                MaterialPageRoute(builder: (context) => QGLoginPage()), 
                (route) => false // 清除所有历史路由
              );
              
              // Navigator.of(context).pushNamedAndRemoveUntil(
              //     PageMainTab, arguments: 0, (route) => false);
            },
            child: Container(
              width: 250.rpx,
              height: 45.rpx,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                gradient: const LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: [Color(0xFF4AE3FF), Color(0xFF44FFF0)],
                ),
                borderRadius: BorderRadius.circular(19.rpx),
              ),
              child: Text(
                '确认',
                style: TextStyle(
                    fontSize: 14.rpx,
                    fontWeight: FontWeight.bold,
                    color: Color(0xFF111111)),
              ),
            )),
            SizedBox(height: 10.rpx,),
        TextButton(
            onPressed: () {
              Navigator.of(context).pop();
            },
            child: Container(
              width: 135.rpx,
              height: 40.rpx,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10.rpx)),
              child: Text(
                '取消',
                style: TextStyle(
                    fontSize: 14.rpx,
                    fontWeight: FontWeight.bold,
                    color: Color(0xFF989EA4)),
              ),
            )),
        
      ],
    );
  }
}
